#include "task.h"

// #define DEBUG_PROGRAM

Task *createTask(callback work_function, void *args) {
    Task *task = malloc(sizeof(Task));
    if (task == NULL) {
# ifdef DEBUG_PROGRAM
        printf("Task Apply Form Memory Fail!\n");
# endif
        return NULL;
    }

    task->args = args;
    task->work_function = work_function;

# ifdef DEBUG_PROGRAM
    // printf("Create Task Success!\n");
# endif
    return task;
}

void destroyTask(Task *task) {
    free(task->args);
    task->args = NULL;

    free(task);
    task = NULL;

# ifdef DEBUG_PROGRAM
    printf("Destroy Task Success!\n");
# endif
}

void executeTask(Task *task) {
    task->work_function(task->args);
}